package cloudInformation.controller;

import cloudEntity.dto.user.SmartUserMoralEducationDetailsDTO;
import cloudEntity.dto.user.SmartUserMoralEducationDetailsUpdateDTO;
import cloudEntity.utils.ResultUtils;
import cloudEntity.vo.PageBeanVO;
import cloudEntity.vo.user.SmartUserMoralEducationDetailsVO;
import cloudInformation.annotate.AuthCheck;
import cloudInformation.mapper.SmartUserMoralEducationDetailsMapper;
import cloudInformation.service.SmartUserMoralEducationDetailsService;
import huang.cloudUserApi.AuthFeignClient;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: Smart School
 * @ClassName UserMoralEducationDetailsController
 * @description: 学生德育 明细控制器
 * @author: 陈智博
 * @create: 2025-04-15 10:20
 * @Version 1.0
 **/
@RestController
@RequestMapping(value = "/moral/education")
@Tag(name = "用户德育细节控制器")
public class UserMoralEducationDetailsController {

    @Autowired
    private AuthFeignClient authFeignClient;

    // 注入 Mapper
    @Autowired
    private SmartUserMoralEducationDetailsMapper smartUserMoralEducationDetailsMapper;

    @Autowired
    private SmartUserMoralEducationDetailsService smartUserMoralEducationDetailsService;

    @Operation(summary = "获取用户德育明细")
    @RequestMapping(value = "/getUser",method = RequestMethod.GET)
    public ResultUtils<List<SmartUserMoralEducationDetailsVO>> getUser(){
        String sysUserUid = authFeignClient.smartUser().getSysUserUid();
        return ResultUtils.success(smartUserMoralEducationDetailsMapper.getMoralEducationDetails(sysUserUid));
    }

    @Operation(summary = "新增德育明细")
    @Parameter(name = "smartUserMoralEducationDetailsDTO",description = "用户德育明细DTO",required = true)
    @RequestMapping(value = "/add/education/details",method = RequestMethod.POST)
    @AuthCheck(values = "ROLE_TEACHER")
    public ResultUtils createEducationDetails(@RequestBody SmartUserMoralEducationDetailsDTO smartUserMoralEducationDetailsDTO)
    {
        Integer i = smartUserMoralEducationDetailsMapper.insertEducationDetails(smartUserMoralEducationDetailsDTO);
        if(i>0)
        {
            return ResultUtils.success("新增德育明细成功!");
        }
        return ResultUtils.failed("新增德育明细失败!");
    }

    @Operation(summary = "修改德育明细")
    @Parameter(name = "smartUserMoralEducationDetailsDTO",description = "德育明细详情DTO实体",required = true)
    @RequestMapping(value = "/update/education/details",method = RequestMethod.POST)
    @AuthCheck(values = "ROLE_TEACHER")
    public ResultUtils updateEducationDetails(@RequestBody SmartUserMoralEducationDetailsUpdateDTO smartUserMoralEducationDetailsUpdateDTO)
    {
        Integer i = smartUserMoralEducationDetailsService.updateSmartMoralEducationDetails(smartUserMoralEducationDetailsUpdateDTO);
        if (i>0)
        {
            return ResultUtils.success("修改德育明细成功!");
        }
        return ResultUtils.failed("修改德育明细失败!");
    }

    @Operation(summary = "分页查询学生德育明细")
    @Parameters({
            @Parameter(name = "t",description = "人名",required = false),
            @Parameter(name = "n",description = "页码",required = false),
            @Parameter(name = "s",description = "条数",required = false)

    })
    @RequestMapping(method = RequestMethod.GET,value = "/get/byPage")
    private ResultUtils GetEducationDetailsByPage(@RequestParam(value = "t",required = false,defaultValue = "") String personName,
                                                  @RequestParam(value = "n",required = false,defaultValue = "1") Integer pageNum,
                                                  @RequestParam(value = "s",required = false,defaultValue = "10") Integer pageSize)
    {
        PageBeanVO<SmartUserMoralEducationDetailsVO> smartUserMoralEducationDetailsVOPageBeanVO = smartUserMoralEducationDetailsService.GetEducationDetailsByPageAndLikeName(personName,pageNum,pageSize);
        return ResultUtils.success(smartUserMoralEducationDetailsVOPageBeanVO);
    }

    @Operation(summary = "删除学生德育记录")
    @Parameter(name = "ids",description = "ids",required = true)
    @RequestMapping(method = RequestMethod.DELETE,value = "/delete")
    public ResultUtils DeleteEducationDetails(@RequestParam(value = "ids",required = true) String EducationDetailsIds)
    {
        Integer i = smartUserMoralEducationDetailsMapper.deleteEducationDetails(EducationDetailsIds);
        if(i>0)
        {
            return ResultUtils.success("删除记录成功!");
        }
        return ResultUtils.failed("删除记录失败!");
    }

}
